import { PrismaClient } from '@prisma/client'

const prisma = new PrismaClient()

async function main() {
	// 创建管理员用户
	await prisma.user.upsert({
		where: { email: 'admin@example.com' },
		update: {},
		create: {
			email: 'admin@example.com',
			username: 'admin',
			nickname: '管理员',
			password: '123456',
			role: 'admin',
		},
	})

	// 创建3个测试用户
	const testUsers = [
		{
			email: 'zhangsan@example.com',
			username: 'zhangsan',
			nickname: '张三',
			password: '123456',
			gender: 'male',
			avatar: '/default-avatar.png',
		},
		{
			email: 'lisi@example.com',
			username: 'lisi',
			nickname: '李四',
			password: '123456',
			gender: 'male',
			avatar: '/default-avatar.png',
		},
		{
			email: 'wangwu@example.com',
			username: 'wangwu',
			nickname: '王舞',
			password: '123456',
			gender: 'female',
			avatar: '/default-avatar.png',
		},
		{
			email: 'zhaoliu@example.com',
			username: 'zhaoliu',
			nickname: '赵六',
			password: '123456',
			gender: 'female',
			avatar: '/default-avatar.png',
		},
	]

	for (const user of testUsers) {
		await prisma.user.upsert({
			where: { email: user.email },
			update: {},
			create: user,
		})
	}
}

main()
	.then(async () => {
		await prisma.$disconnect()
	})
	.catch(async (e) => {
		console.error(e)
		await prisma.$disconnect()
		process.exit(1)
	})
